<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<!-- <link rel="shortcut icon" href="img/logo.ico" /> -->
		<title>会员管理</title>
    <link href="plugin/date/date.css" rel="stylesheet">
	<link rel="stylesheet" href="images/jquery.Jcrop.min.css">
	<link href="bootstrap/css/bootstrap3.min.css" rel="stylesheet">
    <link href="//netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
	<link rel="stylesheet" href="css/nav.css" />
	<style media="screen">
	#croppingBox {min-width: 400px;}
	.jcrop-holder {margin: 0 auto;}
	</style>
  </head>
  <body>
    <!--导航-->
    <nav class="navbar navbar-inverse">
      <div class="container-fluid">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-2">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
	          	<a class="navbar-brand" href=""><img src="images/admin_logo.png" alt=""></a>
        </div>

        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-2">
          <ul class="nav navbar-nav" id="nav">

          </ul>
          <ul class="nav navbar-nav navbar-right">
            <li class="dropdown">
              <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">欢迎您：<span id="uname"></span><span class="caret"></span></a>
              <ul class="dropdown-menu" role="menu">
                <li><a href="change_pass.html">修改密码</a></li>
                <li><a id="loginOut" href="#">退出登陆</a></li>
              </ul>
            </li>
          </ul>
        </div>
      </div>
    </nav>
    <div class="container-fluid">
			<div class="row bcert-box">
        <ol class="breadcrumb">
          <li><a href="javascript:;">主页</a></li>
          <li>会员管理</li>
          <li class="active">会员管理</li>
        </ol>

        <form class="form-inline searchForm" id="">
          <div class="form-group">
            <span class="theme-title">会员类型:</span>
            <select class="form-control drop-down" name='operationType' id="memberType">
              <option value="">全部</option>
              <option value="1">普通会员</option>
              <option value="2">银牌小卫士</option>
			  <option value="3">金牌小卫士</option>
			  <option value="4">合作方</option>
            </select>
          </div>
		  <!-- <div class="form-group">
            <span class="theme-title">会员状态:</span>
            <select class="form-control drop-down" name='operationType' id="member_state">
              <option value="">全部</option>
              <option value="1">禁止登录</option>
              <option value="0">允许登录</option>
            </select>
          </div> -->
          <div class="form-group">
              <input type="text" class="form-control" style="padding-left:12px;" name="userId" id="member" placeholder="手机号/会员昵称/姓名">
          </div>
          <div class="form-group">
              <input type="text" class="form-control" style="padding-left:12px;" name="orderNo" id="inviterMobile" placeholder="推荐人手机号">
          </div>
          <div class="form-group">
              <input type="text" class="form-control" style="padding-left:12px;" name="startTime" title="错误"
               readonly="readonly"
               data-container="body"
               data-toggle="popover"
               data-placement="bottom"
               data-content="开始时间不能大于结束时间!"
               id="startTime" placeholder="开始时间">
          </div>
          <div class="form-group">
              <input type="text" class="form-control" style="padding-left:12px;" readonly="readonly" name="endTime" id="endTime" placeholder="结束时间">
          </div>
          <div class="form-group">
            <button type="button" class="btn btn-primary btn-success" id="Reset"></span>重置</button>
            <button type="button" class="btn btn-primary btn-default" id="QueryBtn" data-toggle="button" aria-pressed="false" autocomplete="off">查询</button>
            <!-- <button type="button" class="btn btn-primary btn-success" id="dlexcle"></span>&nbsp;导出excle</button> -->
			<button type="button" class="btn btn-primary btn-success addUser">新增会员</button>
          </div>
        </form>
        <div class="table">
          <table class="table table-bordered table-striped" id="integralList">

          </table>
        </div>
      </div>
      <!-- 分页 -->
        <nav aria-label="...">
          <div class="">
            <span id="pageNum">共&nbsp;<strong></strong>&nbsp;页&nbsp;/&nbsp;</span><span id="totalNum">&nbsp;<strong>0</strong>&nbsp;条数据</span>
          </div>
          <ul id="example"></ul>
        </nav>
    </div>

	<!-- 编辑 -->
	<div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" id="entinfo">
	  <div class="modal-dialog modal-lg" role="document">
		  <div class="modal-content">
	  	  <div class="modal-header">
	  		<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
	  		<h4 class="modal-title" id="myLargeModalLabel">合作方授权</h4>
	  	  </div>
	  	  <div class="modal-body" style="overflow:auto">
			  <div class="form-group">
                <label class="col-sm-2 control-label goods-lb-l">合作方等级</label>
                <div class="col-sm-10 goods-lb-r" style="padding-top:7px;" id="partnerId">
                  <!-- <label><input type="radio" name="optionsRadios" value="">省级合作方</label>
                  <label><input type="radio" name="optionsRadios" value="">市级合作方</label>
                  <label><input type="radio" name="optionsRadios" value="">县级合作方</label> -->
                </div>
              </div>
	  		  <div class="form-group">
	  			<label class="col-sm-2 control-label goods-lb-l">合同号</label>
	  			<div class="col-sm-10 goods-lb-r"><input type="text" class="form-control" id="contractNo" placeholder="合同号"></div>
	  		  </div>
	  	  </div>
	  	  <div class="modal-footer">
	  		<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
	  		<button type="button" class="btn btn-primary" id="entBtn">确认提交</button>
	  	  </div>
	  	</div><!-- /.modal-content -->
	  </div>
	</div>

	<div class="modal fade" tabindex="-1" id="editUser" role="dialog" aria-labelledby="">
		<div class="modal-dialog modal-lg" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span>
					</button>
						<h4 class="modal-title" id="myLargeModalLabel">会员信息</h4>
				</div>
				<div class="modal-body" style="overflow:auto">
					<!-- <div class="form-group">
						<label class="col-sm-2 control-label goods-lb-l">会员id</label>
						<div class="col-sm-10 goods-lb-r">
							<input type="text" class="form-control" id="memberId" disabled placeholder="会员id">
						</div>
					</div> -->
					<div class="form-group">
						<label class="col-sm-2 control-label goods-lb-l">手机号</label>
						<div class="col-sm-10 goods-lb-r">
							<input type="text" class="form-control" id="memberMobile" placeholder="手机号">
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-2 control-label goods-lb-l">密码</label>
						<div class="col-sm-10 goods-lb-r">
							<input type="password" class="form-control" id="memberPasswd" placeholder="密码">
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-2 control-label goods-lb-l">会员名称</label>
						<div class="col-sm-10 goods-lb-r">
							<input type="text" class="form-control" id="memberName" placeholder="会员名称">
						</div>
					</div>
					<div class="form-group">
					   	<label class="col-sm-2 control-label goods-lb-l">所在地区</label>
					   	<div class="col-sm-3 goods-lb-r">
							<select class="form-control drop-down" id="memberProvinceid">
							   <!-- <option value="0">请选择套餐</option>
							   <option value="1">套餐1</option>
							   <option value="2">套餐2</option>
							   <option value="3">套餐3</option> -->
							</select>
					   	</div>
						<div class="col-sm-3 goods-lb-r">
							<select class="form-control drop-down" id="memberCityid">
							   <!-- <option value="0">请选择套餐</option>
							   <option value="1">套餐1</option>
							   <option value="2">套餐2</option>
							   <option value="3">套餐3</option> -->
							</select>
					   	</div>
						<div class="col-sm-3 goods-lb-r">
							<select class="form-control drop-down" id="memberAreaid">
							   <!-- <option value="0">请选择套餐</option>
							   <option value="1">套餐1</option>
							   <option value="2">套餐2</option>
							   <option value="3">套餐3</option> -->
							</select>
					   	</div>
					</div>
					 <!-- <div class="form-group">
						 <label class="col-sm-2 control-label goods-lb-l">真实姓名</label>
						 <div class="col-sm-10 goods-lb-r">
							 <input type="text" class="form-control" id="suserName" placeholder="真实姓名">
						 </div>
					 </div> -->
					 <div class="form-group">
						 <label class="col-sm-2 control-label goods-lb-l">性别</label>
						 <div class="col-sm-10 goods-lb-r" style="padding-top:7px;" id="memberSex">
							 <label>
								 <input type="radio" name="memberSexRadio" id="memberSex0" value="0">保密</label>
							 <label>
								 <input type="radio" name="memberSexRadio" value="1">男</label>
								 <label>
									 <input type="radio" name="memberSexRadio" value="2">女</label>
						 </div>
					 </div>
					 <div class="form-group">
						 <label class="col-sm-2 control-label goods-lb-l">QQ</label>
						 <div class="col-sm-10 goods-lb-r">
							 <input type="text" class="form-control" id="memberQq" placeholder="QQ">
						 </div>
					 </div>
					 <div class="form-group">
						 <label class="col-sm-2 control-label goods-lb-l">阿里旺旺</label>
						 <div class="col-sm-10 goods-lb-r">
							 <input type="text" class="form-control" id="memberWw" placeholder="阿里旺旺">
						 </div>
					 </div>
					<!-- <div class="form-group">
						<label class="col-sm-2 control-label goods-lb-l">上传头像</label>
						<div class="col-sm-10 goods-lb-r">
							<form id="add" enctype="multipart/form-data">
								<input type="file" multiple="" onchange="imgup(this)" class="form-control"  name="file" placeholder="上传头像"> -->
								<!-- <input type="file" name="filepath" multiple="" id="imgFile" onchange="imgup(this)"> -->
							<!-- </form>
						</div>
					</div> -->
					<div class="stateList" style="display:none;">
						<div class="form-group">
							<label class="col-sm-2 control-label goods-lb-l">允许发表言论</label>
							<div class="col-sm-10 goods-lb-r" style="padding-top:7px;" id="isAllowtalk">
								<label>
									<input type="radio" name="isAllowtalkRadio" id="status1" value="1">允许</label>
								<label>
									<input type="radio" name="isAllowtalkRadio" id="status0" value="0">禁止</label>
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-2 control-label goods-lb-l">举报商品</label>
							<div class="col-sm-10 goods-lb-r" style="padding-top:7px;" id="informAllow">
								<label>
									<input type="radio" name="informAllowRadio" value="1">允许</label>
								<label>
									<input type="radio" name="informAllowRadio" value="0">禁止</label>
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-2 control-label goods-lb-l">允许购买商品</label>
							<div class="col-sm-10 goods-lb-r" style="padding-top:7px;" id="isBuy">
								<label>
									<input type="radio" name="isBuyRadio" value="1">允许</label>
								<label>
									<input type="radio" name="isBuyRadio" value="0">禁止</label>
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-2 control-label goods-lb-l">允许登陆</label>
							<div class="col-sm-10 goods-lb-r" style="padding-top:7px;" id="memberState">
								<label>
									<input type="radio" name="memberStateRadio" value="1">允许</label>
								<label>
									<input type="radio" name="memberStateRadio" value="0">禁止</label>
							</div>
						</div>
					</div>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
					<button type="button" class="btn btn-primary" id="entBtns">确认提交</button>
				</div>
			</div>
			<!-- /.modal-content -->
		</div>
		<!-- /.modal-dialog -->
	</div>

	<div class="modal fade" tabindex="-1" role="dialog" id="croppingBox">
	  <div class="modal-dialog" role="document">
		<div class="modal-content">
		  <div class="modal-header">
			<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
			<h4 class="modal-title">头像裁剪</h4>
		  </div>
		  <div class="modal-body" id="imgBoxc">

		  </div>
		  <div class="modal-footer">
			<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
			<button type="button" class="btn btn-primary" id="btn">提交</button>
		  </div>
		</div><!-- /.modal-content -->
	  </div><!-- /.modal-dialog -->
	</div><!-- /.modal -->
	<input type="hidden" id="x" name="x" />
	<input type="hidden" id="y" name="y" />
	<input type="hidden" id="w" name="w" />
	<input type="hidden" id="h" name="h" />
  </body>
  <script src="js/jquery.min.js"></script>
  <script type="text/javascript" src="plugin/layer/layer.js"></script>
  <script type="text/javascript" src="js/cookie.js"></script>
  <script type="text/javascript" src="js/common.js"></script>
  <script type="text/javascript" src="js/ajax.js"></script>
  <script src="js/jquery.Jcrop.min.js"></script>
  <script type="text/javascript" src="bootstrap/js/bootstrap.min.js" ></script>
  <script type="text/javascript" src="js/bootstrap-paginator.js"></script>
  <script type="text/javascript" src="plugin/date/date.js"></script>
  <script type="text/javascript" src="js/md5.min.js" charset="utf-8"></script>
  <script type="text/javascript" src="plugin/date/date.zh-CN.js"></script>
  <script>
  var ctServerURL = serverURL + '/platform/getWmArea';
  var userAddURL = '';
  $("document").ready(function(){
    tableList()
    userType()
	provinces()
  })
 var pageUrls =  serverURL + '/platform/queryMember';
  //分页
  function tableList(){
	  data = {
		  'member':$('#member').val(),
		  'memberType':$('#memberType').val(),
		  'inviterMobile':$('#inviterMobile').val(),
		  'member_state':$('#memberState').val(),
		  'startTime':$('#startTime').val(),
		  'endTime':$('#endTime').val(),
		  'page': page,
		  'pageSize': pagesize
	  }
	  data.page = 1
	  ajax(
		  pageUrls,
		  data,
		  pageNumList,
		  'post',
		  'json'
	  )
  }

  //数据渲染
  function OpendList(res){
    var result = '';
    $('#integralList').empty();
    $('#integralList').append(
      '<tr>' +
      '<th>会员id</th>' +
	//'<th>会员头像</th>' +
      '<th>真实姓名</th>' +
      '<th>手机号</th>' +
      '<th>推荐人手机号</th>' +
	  '<th>无忧券</th>' +
	  '<th>物券总额</th>' +
	//   '<th>冻结物券总额</th>' +
	//   '<th>冻结余额</th>' +
	  '<th>金券</th>' +
	//   '<th>会员状态</th>' +
	  '<th>注册地</th>' +
	  '<th>认证状态</th>' +
	  '<th>会员类型</th>' +
	  '<th>注册时间</th>' +
      '<th class="text-center">操作</th>' +
      '</tr>'
    );
    for (var i = 0; i < res.data.list.length; i++) {
		var isReal = ''
		if (res.data.list[i].isReal == 0) {
			isReal = '未实名认证'
		}else if (res.data.list[i].isReal == 1) {
			isReal = '已实名认证'
		}
		// var memberType = ''
		// if (res.data.list[i].memberType == 1) {
		// 	memberType = '普通会员'
		// }else if (res.data.list[i].memberType == 2) {
		// 	memberType = '银牌会员'
		// }else if (res.data.list[i].memberType == 3) {
		// 	memberType = '金牌会员'
		// }else if (res.data.list[i].memberType == 4) {
		// 	memberType = '合作方'
		// }
		var partnerId = ''
		if (res.data.list[i].partnerId == 1) {
			partnerId = '省级代理'
		}else if (res.data.list[i].partnerId == 2) {
			partnerId = '市级代理'
		}else if (res.data.list[i].partnerId == 3) {
			partnerId = '县级代理'
		}else {
			partnerId = ''
		}
        var time = getMyDate(res.data.list[i].createTime);
		var hz = res.data.list[i].memberType!='省级合作方' && res.data.list[i].memberType!='市级合作方' && res.data.list[i].memberType!='县级合作方';
		// var mz = res.data.list[i].memberType=='普通会员' && res.data.list[i].memberType=='银牌小卫士';
        result +=
               '<tr>'+
                 '<td>'+ res.data.list[i].memberId +'</td>'+
                //  '<td><img src="'+ res.data.list[i].memberAvatar +'" alt="..." style="width: 40px; height: 40px;" class="img-circle img-thumbnail"></td>'+
                 '<td>'+ res.data.list[i].memberTruename +'</td>'+
                 '<td>'+ res.data.list[i].memberMobile +'</td>'+
                 '<td>'+ res.data.list[i].inviterMobile +'</td>'+
                 '<td>'+ res.data.list[i].bond +'</td>'+
				 '<td>'+ res.data.list[i].coupon +'</td>'+
				//  '<td>'+ res.data.list[i].freezeCoupon +'</td>'+
				//  '<td>'+ res.data.list[i].freezeBalance +'</td>'+
				 '<td>'+ res.data.list[i].balance +'</td>'+
				//  '<td>'+ res.data.list[i].memberExppoint +'</td>'+
				//  '<td>'+ res.data.list[i].memberState +'</td>'+
				 '<td>'+ res.data.list[i].provinceId + res.data.list[i].cityId +res.data.list[i].areaId +'</td>'+
				 '<td>'+ isReal +'</td>'+
				 '<td>'+ res.data.list[i].memberType + '</td>'+
				 '<td>'+ res.data.list[i].addTime + '</td>'+
                 '<td class="text-center integral_operation"><button type="" data-id="'+ res.data.list[i].memberId +'" class="btn btn-primary btn-sm btn-default editor" data-toggle="modal" data-target="">编辑</button>&nbsp;'
				 if (hz && res.data.list[i].isReal==1) {
					if(res.data.list[i].memberType!='金牌小卫士'){
 						result += '<button type="button" data-id="'+ res.data.list[i].memberId +'" onclick="addXws('+ res.data.list[i].memberId +')"  class="btn btn-success btn-sm">授权金牌小卫士</button>&nbsp;'
 					}
					result += '<button type="button" data-id="'+ res.data.list[i].memberId +'"  class="btn btn-success btn-sm authorise" data-toggle="modal" data-target=".bs-example-modal-lg">授权合作方</button>'
				}else{
					result +=''
				}
                result +='</td>'+'</tr>'
    }
    $('#integralList').append(result)
  }
  //查询
  $('#QueryBtn').click(function(){
    tableList()
  })
  $(document).on('click', '.editor', function() {
	$('#editUser').modal();
  })

  function compareDate(startTime, endTime) {
         return new Date(startTime).getTime() > new Date(endTime).getTime();
     }

     function checkStartAndEndTime() {
         if(compareDate($('#startTime').val(), $('#endTime').val())){
             $('#startTime').addClass("card-warning");
             $('#startTime').popover('show');

         }else{
             $('#startTime').removeClass("card-warning");
             $('#startTime').popover('hide')
         }
     }

     //时间选择
     $("#startTime").datetimepicker({
         format: "yyyy-mm-dd",
         autoclose: true,
         todayBtn: true,
         todayHighlight: true,
        //  endTime:new Date(),
         showMeridian: true,
         pickerPosition: "bottom-left",
         language: 'zh-CN',//中文，需要引用zh-CN.js包
         startView: 2,//月视图
         minView: 2,//日期时间选择器所能够提供的最精确的时间选择视图
     }).change(function () {
         checkStartAndEndTime();
     });
     $("#endTime").datetimepicker({
         format: "yyyy-mm-dd",
         autoclose: true,
         todayBtn: true,
         todayHighlight: true,
        //  endTime:new Date(),
         showMeridian: true,
         pickerPosition: "bottom-left",
         language: 'zh-CN',//中文，需要引用zh-CN.js包
         startView: 2,//月视图
         minView: 2,//日期时间选择器所能够提供的最精确的时间选择视图
     }).change(function () {
         checkStartAndEndTime();
     });
	 $(document).on('click', '.authorise', function() {
		id = $(this).attr('data-id')
		$('#entBtn').attr('data-id',id)
	 })

	//授权
	 $('#entBtn').click(function(){
		 var id = $(this).attr('data-id');
		 $.ajax({
 			url: serverURL +  '/platform/setPartner',
 			type: "post",
 			dataType: "json",
 			data: {
 			  'memberId':id,
			  'partnerId':$("input[name='optionsRadios']:checked").val(),
			  'contractNo':$('#contractNo').val()
 			},
 			success: function (data) {
 				console.log(data.msg)
 				layer.msg(data.msg)
 				if (data.code == 400) {
 					alert("登陆超时请重新登陆")
 					window.location.href = "login.html";
 				}else if (data.code == 200) {
					$('#entinfo').modal('hide')
 					tableList();
 				}
 			}
 		});
	 })

	 function userType(){
		var data = null
 		var callback = function(res){
			var html = ''
			for (var i = 0; i < res.data.list.length; i++) {
			 html += '<label><input type="radio" name="optionsRadios" value="' +res.data.list[i].id +'">'+ res.data.list[i].name+'</label>'
			}
			$('#partnerId').html(html);
 		}
 		ajax(
 			serverURL + '/platform/partnerLevelDict',
 			data,
 			callback,
 			'post',
 			'json'
 		)
	}
	function updateCoords(c) {
		$('#x').val(c.x);
		$('#y').val(c.y);
		$('#w').val(c.w);
		$('#h').val(c.h);
		// console.log(c.x,c.y,c.w,c.h)
	};
	$('#croppingBox').on('hidden.bs.modal', function (e) {
		$('#imgBoxc').html('')
	})
	function imgup(upImg) {
	 var datas = new FormData($('#add')[0]);
	 $.ajax({
		 url: serverURL + '/platform/uploadAvatar',
		 type: "post",
		 dataType: "json",
		 cache: false,
		 contentType: false,
		 processData: false,
		 data:datas,
		 xhrFields: {
			withCredentials: true
		 },
		 success: function (data) {
			 if (data.code == 200) {
				 var srcs = getObjectURL(upImg.files[0]);
				$('#imgBoxc').html('<img id="element_id" src="' + srcs + '">')
				$('#croppingBox').modal();
				var jcropApi;
				$('#element_id').Jcrop({
					allowSelect: true,
					baseClass: 'jcrop',
					aspectRatio: 1,
					boxWidth:400,
					boxHeight:400,
					onSelect: updateCoords
				}, function() {
					jcropApi = $(this);
				});
			 }
		 }
	 });
	 return false
	}
	$('#btn').click(function() {
		var data = {
			'x': parseInt($('#x').val()),
			'y': parseInt($('#y').val()),
			'width': parseInt($('#w').val()),
			'height': parseInt($('#h').val())
		}
		var callback = function(res){
			window.location.href=data.data[0]
		}
		ajax(
			serverURL + '/platform/cutAvatar',
			data,
			callback,
			'post',
			'json'
		)
	})

	//状态选择
	function radios(obj,val){
		obj.each(function() {
			if($(this).val() == val){
				$(this).prop("checked",true);
			}
		});
	}

	$('#editUser').on('hidden.bs.modal', function (e) {
		$('#entBtn').attr('data-id','');
		$("input[type='text'").val(null)
		$("input[type='password'").val(null)
		$("input[type='radio']").removeAttr('checked');
		$('#memberProvinceid').val('0')
		$('#memberCityid').html('<option value="0">请选择城市</option>')
		$('#memberAreaid').html('<option value="0">请选择区县</option>')
		$('.stateList').hide();
		$('#entBtns').attr('data-id',null)
	})

	//详情
	$(document).on('click', '.editor', function() {
		$('#editUser').modal()
		// $('.stateList').show();
		userAddURL = '/platform/editMember'
		var id = $(this).attr('data-id')
		$('#entBtns').attr('data-id',id)
		var data = {
			memberId:id
		}
 		var callback = function(res){
			$('#memberMobile').val(res.data.memberMobile)
			$('#memberPasswd').val(res.data.passwd)
			$('#memberName').val(res.data.memberName)
			$('#memberQq').val(res.data.memberQq)
			$('#memberWw').val(res.data.memberWw)
			radios($("#memberSex input[name='memberSexRadio']"),res.data.memberSex)
			radios($("#isAllowtalk input[name='isAllowtalkRadio']"),res.data.isAllowtalk)
			radios($("#memberState input[name='memberStateRadio']"),res.data.memberState)
			radios($("#informAllow input[name='informAllowRadio']"),res.data.informAllow)
			radios($("#isBuy input[name='isBuyRadio']"),res.data.isBuy)
			$('#memberProvinceid').val(res.data.provinceId)
			city(res.data.provinceId)
			$('#memberCityid').val(res.data.cityId)
			area(res.data.cityId)
			$('#memberAreaid').val(res.data.areaId)
 		}
 		ajax(
 			serverURL + '/platform/getMemberInfo',
 			data,
 			callback,
 			'post',
 			'json'
 		)
	})

	//建立一個可存取到該file的url
	function getObjectURL(fis) {
		var urls = null;
		// 下面函数执行的效果是一样的，只是需要针对不同的浏览器执行不同的 js 函数而已
		// basic
		if (window.createObjectURL != undefined) {
			urls = window.createObjectURL(fis);
			// mozilla(firefox)
		} else if (window.URL != undefined) {
			urls = window.URL.createObjectURL(fis);
			// webkit or chrome
		} else if (window.webkitURL != undefined) {
			urls = window.webkitURL.createObjectURL(fis);
		}
		return urls;
	}

	//获取省份
	function provinces(){
		var data = {
			'areaParentId':''
		}
		var callback = function(res){
			var html = '';
			for (var i = 0; i < res.data.length; i++) {
				html += '<option value="'+ res.data[i].areaId +'">' + res.data[i].areaName + '</option>'
			}
			$('#memberProvinceid').append(html)
			$('#memberProvinceid').prepend('<option value="0">请选择省份</option>')
			$('#memberProvinceid').val('0')
		}
		ajax(
			ctServerURL,
			data,
			callback,
			'post',
			'json',
			false
		)
	}

	//获取城市
	function city(ctId){
		$.ajax({
            type:"post",
            dataType:'json',
			async: false,
            url:ctServerURL,
            data:{
				'areaParentId':ctId
			},
            success:function(res){
                if(res.code ==200) {
					var html = ''
					for (var i = 0; i < res.data.length; i++) {
						html += '<option value="'+ res.data[i].areaId +'">' + res.data[i].areaName + '</option>'
					}
					$('#memberCityid').html(html)
					$('#memberCityid').prepend('<option value="0">请选择城市</option>')
					$('#memberCityid').val('0')
                }
            }
        })
		$('#memberAreaid').html('<option value="0">请选择区县</option>')
	}

	$('#memberProvinceid').change(function(){
		var ctId = $(this).val()
		if ($('#memberProvinceid').val()== '0') {
			$('#memberCityid').html('<option value="0">请选择城市</option>')
			$('#memberAreaid').html('<option value="0">请选择区县</option>')
		}else {
			city(ctId)
		}
	})

	//获取区县
	function area(ctId){
		$.ajax({
            type:"post",
            dataType:'json',
			async: false,
            url:ctServerURL,
            data:{
				'areaParentId':ctId
			},
            success:function(res){
                if(res.code ==200) {
					var html = ''
					for (var i = 0; i < res.data.length; i++) {
						html += '<option value="'+ res.data[i].areaId +'">' + res.data[i].areaName + '</option>'
					}
					$('#memberAreaid').html(html)
					$('#memberAreaid').prepend('<option value="0">请选择区县</option>')
					$('#memberAreaid').val('0')
                }
            }
        })
	}
	$('#memberCityid').change(function(){
		var ctId = $(this).val()
		if ($('#memberCityid').val()== '0') {
			$('#memberAreaid').html('<option value="0">请选择区县</option>')
		}else {
			area(ctId)
		}
	})

	//新增会员
	$('.addUser').click(function(){
		userAddURL = '/platform/addMember'
		$('#editUser').modal()
		$("input[name='informAllowRadio']")
		$('#memberSex0').prop("checked",true);
		$('#memberCityid').html('<option value="0">请选择城市</option>')
		$('#memberAreaid').html('<option value="0">请选择区县</option>')
	})
	$('#entBtns').click(function(){
		var id = $(this).attr('data-id')
		var password = ''
		if($("input[type='password'").val().length!=32){
			password = md5($("input[type='password'").val())
		}else{
			password = $("input[type='password'").val()
		}
		var data = {
			'memberId':id,
			'memberMobile':$('#memberMobile').val(),
			'memberPasswd':password,
			'memberName':$('#memberName').val(),
			'memberProvinceid':$('#memberProvinceid').val(),
			'memberCityid':$('#memberCityid').val(),
			'memberAreaid':$('#memberAreaid').val(),
			'memberSex':$("input[name='memberSexRadio']:checked").val(),
			'isAllowtalk':$("input[name='isAllowtalkRadio']:checked").val(),
			'informAllow':$("input[name='informAllowRadio']:checked").val(),
			'isBuy':$("input[name='isBuyRadio']:checked").val(),
			'memberState':$("input[name='memberStateRadio']:checked").val(),
			'memberQq':$('#memberQq').val(),
			'memberWw':$('#memberWw').val()
		}
		var callback = function(res){
			$('#editUser').modal('hide')
			tableList()
		}
		ajax(
			serverURL+userAddURL,
			data,
			callback,
			'post',
			'json',
			false
		)
	})
	//设置小卫士
	function addXws(memberId){
		layer.confirm('确定要授权吗？', {
			btn: ['确认','取消'] //按钮
		}, function(){
			var data = {
				'memberId':memberId
			}
			var callback = function(res){
				tableList()
			}
			ajax(
				serverURL + '/platform/setGold',
				data,
				callback,
				'post',
				'json'
			)
		}, function(){
		});
	}
  </script>
</html>
